library(sf)
library(tidyverse)
library(ggplot2)
library(tidycensus)
library(tigris)
library(spData)



#the tigris packages makes it very easy to load shapefiles of commonly used geographies
states <- states(cb=TRUE, resolution = "20m")

ggplot() + 
  geom_sf(data = states)

#shift alaska, hawaii, and PR, don't include other territories 
states <- states(cb=TRUE, resolution = "20m") %>% shift_geometry()

states$rape <- ifelse(states$STUSPS %in% c("AL", "MO", "TN", "SD", "TX", "AR"), 1, 0)

states$rape_enjoined <- ifelse(states$STUSPS %in% c("AL", "MO", "TN", "SD", "TX", "AR"), "No Rape Exception", ifelse(states$STUSPS %in%  c("KY", "LA", "OK", "AZ", "WI", "MI", "WV", "FL", "OH"), "No Rape Exception,\nCourt Enjoined", "Rape Exception"))

states$rape_enjoined <- factor(states$rape_enjoined, levels = c("No Rape Exception", "No Rape Exception,\nCourt Enjoined", "Rape Exception"))


  ggplot() + 
  geom_sf(data = states, aes(fill = rape_enjoined)) + 
  scale_fill_manual(values=c("dark red", "dark orange", "#698a6b")) + 
  labs(fill = "", title = "Post-Dobbs Abortion Status", subtitle = "State law regarding abortion if the pregnancy is the result of rape ", caption = "Data: https://www.poynter.org/fact-checking/2022/post-roe-v-wade-state-bans-no-exceptions-rape-incest/, July 20, 2022") + 
    theme_void() +
    theme(axis.text.x=element_blank(),
  axis.ticks.x=element_blank(),
  axis.text.y=element_blank(),
  axis.ticks.y=element_blank(),
  plot.caption = element_text(hjust=2),
  legend.position = "right")
    



